package module4.homework;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class Student {

    //1、首先创建一个集合
    List list = new ArrayList();
   /* FileOutputStream ft = null;*/
   FileOutputStream ft = null;
   ObjectOutputStream oot = null;

   //2、增删改查遍历的操作功能
    public void show1(String name, String number, int age) {
        list.add(new StudentInformation(name, number, age));
    }
    public void show2(int i) {
        if (i <= list.size()) {
            list.remove(i-1);
        }else System.out.println("没有这位学生哦^-^");
    }
    public  void show3(int i, String name, String number, int age) {
        if (i <= list.size()) {
            Object obj = new StudentInformation(name, number, age);
            list.set(i - 1, obj);
        } else {
            System.out.println("没有这位学生哦!");
        }
    }
    public Object show4(String str) {
        for (Object obj : list) {
            if (str.equalsIgnoreCase(((StudentInformation)obj).getName())) {
                return obj;
            }
        }
        return "没有这位学生哦！^-^";
    }
    public void show5() {
        for (Object obj : list) {
            System.out.println(obj);
        }
    }

    public void show6() {
        try {
            ft = new FileOutputStream("e:/a.txt");
            oot= new ObjectOutputStream(ft);
           /* System.out.println("写入中...");*/
            oot.writeObject(list);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                oot.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                ft.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public void show7(List li) {
        list = li;
    }

    public void show8() {
        try {
            ft = new FileOutputStream("e:/a.txt", true);
            oot= new ObjectOutputStream(ft);
            /*System.out.println("写入中...");*/
            oot.writeObject(list);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                oot.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                ft.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}
